package com.aaa.day1107.demo04;

/**
 * @author ${崔灿}
 * @date 2022/11/07 17:04
 **/

public class Singleton {
    private Singleton(){

    }
    //声明一个静态的本类对象---懒汉式
    private static Singleton singleton;
    //提供一个静态方法返回本类对象
    public static Singleton getInstance() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton=new Singleton();
                }
            }
        }
        return singleton;
    }
    public void show(){
        System.out.println("这是show方法");
    }
}
